package net.sk.china.city.controller;

import java.util.List;

import net.sk.china.city.domain.vo.AddHomeProductVO;
import net.sk.china.city.domain.vo.HomeProductInfoVO;
import net.sk.china.city.domain.vo.UpdateHomeProductVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import net.sk.china.city.controller.base.BaseController;
import net.sk.china.city.domain.dto.AjaxResult;
import net.sk.china.city.domain.ArHomeProduct;
import net.sk.china.city.service.IArHomeProductService;
import net.sk.china.city.domain.dto.TableDataInfo;

/**
 * 商品管理Controller
 * 
 * @author gxf
 * @date 2024-03-29
 */
@Api(tags = "义购之家")
@RequiredArgsConstructor
@RestController
@RequestMapping("/yigoHome/product")
public class ArHomeProductController extends BaseController
{
    @Autowired
    private IArHomeProductService arHomeProductService;

    /**
     * 查询商品管理列表
     */
    @ApiOperation("商品列表")
    @PreAuthorize("hasAnyAuthority('yigoHome:product:list')")
    @GetMapping("/list")
    public TableDataInfo list(ArHomeProduct arHomeProduct)
    {
        startPage();
        List<HomeProductInfoVO> list = arHomeProductService.selectArHomeProductList(arHomeProduct);
        return getDataTable(list);
    }

    /**
     * 导出商品管理列表
     */
//    @PreAuthorize("@ss.hasPermi('yigoHome:product:export')")
//    @Log(title = "商品管理", businessType = BusinessType.EXPORT)
//    @PostMapping("/export")
//    public void export(HttpServletResponse response, ArHomeProduct arHomeProduct)
//    {
//        List<ArHomeProduct> list = arHomeProductService.selectArHomeProductList(arHomeProduct);
//        ExcelUtil<ArHomeProduct> util = new ExcelUtil<ArHomeProduct>(ArHomeProduct.class);
//        util.exportExcel(response, list, "商品管理数据");
//    }

    /**
     * 获取商品管理详细信息
     */
    @ApiOperation("商品详情")
    @PreAuthorize("hasAnyAuthority('yigoHome:product:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(arHomeProductService.selectArHomeProductById(id));
    }

    /**
     * 新增商品管理
     */
    @ApiOperation("新增商品")
    @PreAuthorize("hasAnyAuthority('yigoHome:product:add')")
    @PostMapping
    public AjaxResult add(@RequestBody AddHomeProductVO addHomeProductVO)
    {
        return toAjax(arHomeProductService.insertArHomeProduct(addHomeProductVO));
    }

    /**
     * 修改商品管理
     */
    @ApiOperation("修改商品")
    @PreAuthorize("hasAnyAuthority('yigoHome:product:edit')")
    @PutMapping
    public AjaxResult edit(@RequestBody UpdateHomeProductVO updateHomeProductVO)
    {
        return toAjax(arHomeProductService.updateArHomeProduct(updateHomeProductVO));
    }

    /**
     * 删除商品管理
     */
    @ApiOperation("删除商品")
    @PreAuthorize("hasAnyAuthority('yigoHome:product:remove')")
	@DeleteMapping("/{id}")
    public AjaxResult remove(@PathVariable Long[] id)
    {
        return toAjax(arHomeProductService.deleteArHomeProductByIds(id));
    }

}
